<?php

namespace App\Models;

use App\Models\Base\School as BaseSchool;

/**
 * 
 *
 * @property int $id
 * @property string $name 学校名称
 * @property string|null $address 学校地址
 * @property string|null $tel 学校电话
 * @property string|null $memo 备注
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicket> $tickets
 * @property-read int|null $tickets_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\SchoolUser> $users
 * @property-read int|null $users_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkUser> $workUsers
 * @property-read int|null $work_users_count
 * @method static \Illuminate\Database\Eloquent\Builder|School newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|School newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|School onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|School query()
 * @method static \Illuminate\Database\Eloquent\Builder|School whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereMemo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereTel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|School withTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|School withoutTrashed()
 * @mixin \Eloquent
 */
class School extends BaseSchool
{
	protected $fillable = [
		self::NAME,
		self::ADDRESS,
		self::TEL,
		self::MEMO
	];

	public function users()
	{
		return $this->hasMany(SchoolUser::class, SchoolUser::SCHOOL_ID, self::ID);
	}

	public function tickets()
	{
		return $this->hasMany(WorkTicket::class, WorkTicket::SCHOOL_ID, self::ID);
	}

	public function workUsers()
	{
		return $this->belongsToMany(WorkUser::class, 'work_user_schools', 'school_id', 'work_user_id');
	}
	

}
